package com.buffered.homework;

import java.io.*;
import java.util.Comparator;
import java.util.TreeSet;

/**
 * @author げっしょく
 * @date 2021/8/3
 */
public class Test2 {
    public static void main(String[] args) throws IOException {
        /*
        2. 已知文件中存在包含重复内容的字符串，将文件中的数据去重:
    原文：aabbccddeefffffggg
    去重后：abcdefg
         */
        File file = new File("D:\\a.txt");
        FileInputStream fis = new FileInputStream("D:\\a.txt");
        TreeSet<Integer> ts = new TreeSet<>();
        int a ;
        while ((a = fis.read()) != -1){
            ts.add(a);
        }
        FileOutputStream fos = new FileOutputStream(file);
        for (Integer t : ts) {
            fos.write(t);
        }
        fos.flush();
        fis.close();
        fis.close();
    }
}
